CONTENTS | INDEX | PREV | NEXT
setvbuf
NAME
setvbuf - change file pointer's buffering
SYNOPSIS
#include <stdio.h>
int error = setvbuf(fp, buf, mode, size);
FILE *fp;
char *buf;
int mode;
size_t size;
FUNCTION
setvbuf() changes the internal buffer used by stdio. You may specify
a new buffer of any size, change the buffering mode of the file
pointer to fully buffered, line buffered, or unbuffered.
mode:
_IOFBF fully buffered (output flushed only if buffer full)
_IOLBF line buffered (output flushed every newline)
_IONBF unbuffered (no buffering at all)
For _IOFBF and _IOLBF, buf should point to the buffer you wish the
file pointer to use and size should be the size of that buffer (any
size other than 0 is valid).
For_IONBF the buf and size arguments should be passed as NULL
NOTE
!!
If buffering is turned off for a file pointer representing a
console device, the console device is set to unbuffered as well.
If buffering is turned on for a file pointer representing a
console device, the console device is set to buffered as well.
EXAMPLE
#include <stdio.h>
main()
{
int c;
static char iobuf[128];
char buf[256];
setvbuf(stdin, NULL, _IONBF, 0);
printf("Type a character: ");
fflush(stdout);
c = getchar();
printf("c = %dn", c);
setvbuf(stdin, iobuf, _IOLBF, sizeof(iobuf));
printf("Type a line: ");
fflush(stdout);
gets(buf);
printf("You said: %sn", buf);
return(0);
}
INPUTS
FILE *fp; file pointer to change buffering options on
char *buf; new buffer or NULL (_IONBF)
int mode; buffering mode
size_t size; size of new buffer if not NULL, else 0
RESULTS
int error; 0 on success, a negative number on error
(such as illegal arguments)
SEE ALSO
setbuf